package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bean.ImageContext;
import com.dao.ImageContextDao;
import com.service.ImageContextService;
import com.util.LoggerUtil;
import com.util.Pager;
@Service
public class ImageContextServiceImpl implements ImageContextService{
	public static Logger logger=Logger.getLogger(ImageContextServiceImpl.class);
	@Autowired
	private ImageContextDao imageContextDao;

	@Override
	public Map<String, Object> selectPageByZanNum(Integer curPage,
			Integer pageSize,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<ImageContext> pager=imageContextDao.selectPageByZanNum(curPage, pageSize,userId);
			if(pager!=null&&pager.getData().size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		
		return map;
	}

	@Override
	public Map<String, Object> selectPageByTag(Integer curPage,
			Integer pageSize, String imgtags,String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<ImageContext> pager=imageContextDao.selectPageByTag(curPage, pageSize, imgtags,userId);
			if(pager!=null&&pager.getData().size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101"); 
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		
		
		return map;
	}

	@Override
	public Map<String, Object> updateZanNum(String id, String user_id) {
		return imageContextDao.updateZanNum(id, user_id);
	}

	@Override
	public Map<String, Object> updateHostness(String id,String userId,JSONObject logs) {
		return imageContextDao.updateHostness(id,userId,logs);
	}
	
	
}
